package edu.nf.api.controller.shopping;

import com.google.gson.Gson;
import edu.nf.api.controller.BaseController;
import edu.nf.waimai.dao.user.ShoppingDAO;
import edu.nf.waimai.dao.user.impl.ShopPingDAOImpl;
import edu.nf.waimai.model.user.ShoppingCart;
import edu.nf.waimai.model.user.UserShopPingCart;
import edu.nf.waimai.service.user.ShoppingService;
import edu.nf.waimai.service.user.impl.ShoppingServiceImpl;
import org.nf.web.annotation.Model;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.List;

/**
 * @Date 2023/6/19
 * @Author zgm
 * 购物车
 */
public class ShopPingController extends BaseController {
    @RequestMapping("/user/ShopPing/add")
    public View addShopPing(@Model ShoppingCart shoppingCart){
        System.out.println(shoppingCart);
        ShoppingService service = new ShoppingServiceImpl();
        service.addShopPing(shoppingCart);
        return new JsonView(success());
    }
    @RequestMapping("/user/ShopPing/query")
    public View queryShopPing(@RequestParam("uId") int uid,
                              @RequestParam("shopId") int shopId){

        ShoppingService service = new ShoppingServiceImpl();
        List<UserShopPingCart> list = service.listShopping(uid,shopId);
        return new JsonView(success(list));
    }
    @RequestMapping("/user/ShopPing/update")
    public View updateShopPing(@RequestParam("uId") int uid,
                               @RequestParam("shopId") int shopId){
        ShoppingService service = new ShoppingServiceImpl();
        service.updateShopPing(uid, shopId);
        return new JsonView(success());
    }

    @RequestMapping("/ShopPing/update/itemNum")
    public View updateShopPingItemNum(@RequestParam("id") int id,
                               @RequestParam("itemNum") int itemNum){
        ShoppingDAO dao = new ShopPingDAOImpl();
        dao.updateShopPingItemNum(id, itemNum);
        return new JsonView(success());
    }
    @RequestMapping("/ShopPing/delete")
    public View deleteShopPing(@RequestParam("id") int id){
        ShoppingDAO dao = new ShopPingDAOImpl();
        dao.deleteShopPing(id);
        return new JsonView(success());
    }
}
